package cn.ingrun.utils.exceptionHandler;

import cn.ingrun.utils.responseUtil.ResponseUtils;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 全局统一异常处理增强
 **/
@ControllerAdvice
@ResponseBody
public class GlobalExceptionHandler {

    /**
     * API统一异常处理
     **/
    @ExceptionHandler(value = Exception.class)
    public ResponseUtils jsonApiErrorHandler(Exception e) {
        Throwable innerEx = e.getCause();
        if (innerEx == null){
            return ResponseUtils.error(e.getMessage());
        }
        return ResponseUtils.error(innerEx.getMessage());
    }

}